package cn.com.dycc.party_work.education.service;

import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Service;

import cn.com.dycc.common.attach.dao.AttachDao;
import cn.com.dycc.common.attach.entity.Attach;
import cn.com.dycc.party_org.organize.dao.OrganizeDao;
import cn.com.dycc.party_org.organize.entity.OrganizeEntity;
import cn.com.dycc.party_work.education.dao.EducationDao;
import cn.com.dycc.party_work.education.entity.DeptAndEducation;
import cn.com.dycc.party_work.education.entity.Education;
import cn.com.dycc.party_work.education.param.FindEduParam;
import cn.com.dycc.party_work.education_dept.dao.EducationDeptDao;
import cn.com.dycc.party_work.education_dept.entity.EducationDept;
import cn.com.dycc.study_manage.integral.dao.Pb_Integral_Dept_LogDao;
import cn.com.dycc.study_manage.integral.dao.Pb_Integral_RuleDao;
import cn.com.dycc.study_manage.integral.entity.Pb_Integral_Dept_Log;
import cn.com.dycc.study_manage.integral.entity.Pb_Integral_Rule;
import cn.com.dycc.study_manage.integral.param.Pb_Integral_RuleParam;
import cn.com.dycc.util.ArrayUtil;
import cn.com.dycc.util.AttachUtil;
import cn.com.dycc.util.FileUtil;
import cn.com.dycc.util.Paging;
import cn.com.dycc.util.StringUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
 * 
 * Description: 党员教育实现
 * Author: Liket
 * Version: 1.0
 * Create Date Time: 2018年6月27日 下午7:45:36.
 * Update Date Time: 
 * @see
 */
@Service("educationService")
public class EducationServiceImpl implements EducationService{
	@Resource
	private EducationDao educationDao;
	
	@Resource
	private EducationDeptDao educationDeptDao;
	
	@Resource
	private AttachDao attachDao;
	
	@Resource
	private Pb_Integral_RuleDao pb_Integral_RuleDao;
	
	@Resource
	private Pb_Integral_Dept_LogDao pb_Integral_Dept_LogDao;
	
	@Resource
	private OrganizeDao organizeDao;
	
	@Resource(name="paging")
	private Paging paging;
	
	public int addEdu(Education edu,String dept_ids[], HttpServletRequest req) throws EduNotFoundException {
		//System.out.println("e="+edu);
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		//String dept_id = (String) session.getAttribute("dept_id");
		if(user_id==null){
			throw new EduNotFoundException("请重新登录！");
		}
		if(edu==null){
			throw new EduNotFoundException("请填写学习资料");
		}
		if(edu.getEducation_name()==null||edu.getEducation_name().trim().isEmpty()){
			throw new EduNotFoundException("请填写名称");
		}
		if(edu.getEducation_flag()==null||edu.getEducation_flag().trim().isEmpty()){
			throw new EduNotFoundException("请填写类别");
		}
		/*if(edu.getDept_id_send()==null||edu.getDept_id_send().trim().isEmpty()){
			throw new EduNotFoundException("请填写党支部名称");
		}*/
		if(edu.getDate_b()==null||edu.getDate_b().trim().isEmpty()){
			throw new EduNotFoundException("请填写开始时间");
		}
		if(edu.getDate_e()==null||edu.getDate_e().trim().isEmpty()){
			throw new EduNotFoundException("请填写结束时间");
		}
		/*if(edu.getOrder_id()==null||edu.getOrder_id().trim().isEmpty()){
			throw new EduNotFoundException("请填写任务");
		}*/
		if(edu.getEducation_des()==null||edu.getEducation_des().trim().isEmpty()){
			throw new EduNotFoundException("请填写内容");
		}
		try {
			String education_des = StringUtil.decode(edu.getEducation_des());
			edu.setEducation_des(education_des);
		} catch (UnsupportedEncodingException e) {
			throw new EduNotFoundException("内容格式错误");
		}
		String dept_id_send = (String)session.getAttribute("dept_id");
		if(dept_id_send==null||dept_id_send.trim().isEmpty()){
			throw new EduNotFoundException("当前账号不归属党支部，无权限");
		}
		edu.setDept_id_send(dept_id_send);
		edu.setCreate_date(new Timestamp(new Date().getTime()));
		edu.setOpt_user_id(user_id);
		edu.setOrg_id((String)session.getAttribute("org_id"));
		int n = educationDao.addEdu(edu);
		String education_id = edu.getEducation_id();
		if(n!=1){
			throw new EduNotFoundException("添加失败");
		}
		
		
		if(dept_ids!=null&&dept_ids.length>0){
			List<EducationDept> list = new ArrayList<EducationDept>();
			EducationDept eduDept = null;
			for(int i=0;i<dept_ids.length;i++){
				eduDept = new EducationDept();
				eduDept.setEducation_id(education_id);
				eduDept.setDept_id(dept_ids[i]);
				eduDept.setCreate_date(new Timestamp(new Date().getTime()));
				eduDept.setOpt_user_id(user_id);
				eduDept.setOrg_id((String)session.getAttribute("org_id"));
				list.add(eduDept);
			}
			String dept_id_sends[] = {dept_id_send};
			String new_dept_id_sends[] = ArrayUtil.resArray(dept_id_sends,dept_ids);
			
			if(new_dept_id_sends!=null&&new_dept_id_sends.length>0){
				eduDept = new EducationDept();
				eduDept.setEducation_id(edu.getEducation_id());
				eduDept.setDept_id(dept_id_send);
				eduDept.setCreate_date(new Timestamp(new Date().getTime()));
				eduDept.setOpt_user_id(user_id);
				eduDept.setOrg_id((String)session.getAttribute("org_id"));
				list.add(eduDept);
			}
			educationDeptDao.addAllEduDept(list);
		}
		
		
		List<Attach> listAttach = new ArrayList<Attach>();
		
		if(edu.getListAttach()!=null&&!edu.getListAttach().trim().isEmpty()){
			//System.out.println("e1="+edu);
			String str=edu.getListAttach().trim();
			JSONArray json=JSONArray.fromObject(str);
        
			for(int i=0;i<json.size();i++){

				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				
				Attach attach=new Attach();
				attach.setMessage_no(education_id);
				attach.setAttach_type(6);
				attach.setTitle(title);
				attach.setAttach_ext(attach_ext);
				attach.setAttach_path(attach_path);
				attach.setAttach_size(attach_size);				
				attach.setOrg_id((String)session.getAttribute("org_id"));
				attach.setOpt_user_id(user_id);
				listAttach.add(attach);
								
			}        
        }
		
		if(edu.getAttach()!=null&&!edu.getAttach().trim().isEmpty()){
			
			//System.out.println("e2="+edu);
			String str=edu.getAttach().trim();
			JSONArray json=JSONArray.fromObject(str);
        
			for(int i=0;i<json.size();i++){

				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				
				Attach attach2=new Attach();
				attach2.setMessage_no(education_id);
				attach2.setAttach_type(601);
				attach2.setTitle(title);
				attach2.setAttach_ext(attach_ext);
				attach2.setAttach_path(attach_path);
				attach2.setAttach_size(attach_size);				
				attach2.setOrg_id((String)session.getAttribute("org_id"));
				attach2.setOpt_user_id(user_id);
				listAttach.add(attach2);
								
			}        
        }
		List<Attach> newListAttach=FileUtil.moveFile(listAttach,"party_work");
			
		if(newListAttach!=null){
		for(Attach attach:newListAttach){
			attachDao.insertAttach(attach);
				
			}
		}
		
		
		return n;
	}

	//
	public int deleteEdu(String education_id, HttpServletRequest req) throws EduNotFoundException {
		if(education_id==null||education_id.trim().isEmpty()){
			throw new EduNotFoundException("选择要删除的学习");
		}
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		
		int n = educationDao.deleteEdu(education_id,org_id);
		if(n!=1){
			throw new EduNotFoundException("删除失败");
		}
		return n;
	}

	public int deleteAllEdu(String[] education_ids, HttpServletRequest req) throws EduNotFoundException {
		if(education_ids==null){
			throw new EduNotFoundException("选择要删除的学习");
		}
		if(education_ids.length<=0){
			throw new EduNotFoundException("没有要删除的学习");
		}
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		if(user_id==null){
			throw new EduNotFoundException("重新登录");
		}
		int n = educationDao.deleteAllEdu(education_ids);
		if(n<=0){
			throw new EduNotFoundException("删除失败");
		}
		return n;
	}

	public int updateEdu(Education edu, String dept_ids[],HttpServletRequest req) throws EduNotFoundException {
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		String org_id = (String) session.getAttribute("org_id");
		if(user_id==null){
			throw new EduNotFoundException("请重新登录！");
		}
		if(edu==null){
			throw new EduNotFoundException("请填写学习资料");
		}
		if(edu.getEducation_id()==null||edu.getEducation_id().trim().isEmpty()){
			throw new EduNotFoundException("找不到ID");
		}
		if(edu.getEducation_name()==null||edu.getEducation_name().trim().isEmpty()){
			throw new EduNotFoundException("请填写名称");
		}
		if(edu.getEducation_flag()==null||edu.getEducation_flag().trim().isEmpty()){
			throw new EduNotFoundException("请填写类别");
		}
		/*if(edu.getDept_id_send()==null||edu.getDept_id_send().trim().isEmpty()){
			throw new EduNotFoundException("请填写党支部名称");
		}*/
		if(edu.getDate_b()==null||edu.getDate_b().trim().isEmpty()){
			throw new EduNotFoundException("请填写开始时间");
		}
		if(edu.getDate_e()==null||edu.getDate_e().trim().isEmpty()){
			throw new EduNotFoundException("请填写结束时间");
		}
		/*if(edu.getOrder_id()==null||edu.getOrder_id().trim().isEmpty()){
			throw new EduNotFoundException("请填写任务");
		}*/
		
		if(edu.getEducation_des()==null||edu.getEducation_des().trim().isEmpty()){
			throw new EduNotFoundException("请填写内容");
		}
		try {
			String education_des = StringUtil.decode(edu.getEducation_des());
			edu.setEducation_des(education_des);
		} catch (UnsupportedEncodingException e) {
			throw new EduNotFoundException("内容格式错误");
		}
		
		String dept_id_send = (String)session.getAttribute("dept_id");
		if(dept_id_send==null||dept_id_send.trim().isEmpty()){
			throw new EduNotFoundException("当前账号不归属党支部，无权限");
		}
		
		Education oldEdu = educationDao.findEdu(edu.getEducation_id(),org_id);
		if(oldEdu==null){
			throw new EduNotFoundException("ID错误");
		}
		//参数
		Education newEdu = new Education();
		if(!edu.getEducation_name().equals(oldEdu.getEducation_name())){
			newEdu.setEducation_name(edu.getEducation_name());
		}
		if(!edu.getEducation_flag().equals(oldEdu.getEducation_flag())){
			newEdu.setEducation_flag(edu.getEducation_flag());
		}
		if(!dept_id_send.equals(oldEdu.getDept_id_send())){
			newEdu.setDept_id_send(dept_id_send);
		}
		if(!edu.getDate_b().equals(oldEdu.getDate_b())){
			newEdu.setDate_b(edu.getDate_b());
		}
		if(!edu.getDate_e().equals(oldEdu.getDate_e())){
			newEdu.setDate_e(edu.getDate_e());
		}
		if(!edu.getEducation_des().equals(oldEdu.getEducation_des())){
			newEdu.setEducation_des(edu.getEducation_des());
		}
		if(!edu.getOrder_id().equals(oldEdu.getOrder_id())){
			newEdu.setOrder_id(edu.getOrder_id());
		}
		newEdu.setEducation_id(edu.getEducation_id());
		newEdu.setOpt_user_id(user_id);
		newEdu.setOrg_id(org_id);
		int n = educationDao.updateEdu(newEdu);
		if(n!=1){
			throw new EduNotFoundException("修改失败");
		}
		
		//附件
		List<Attach> listAttach = new ArrayList<Attach>();		
		if(edu.getListAttach()!=null&&!edu.getListAttach().trim().isEmpty()){
			//System.out.println("e2="+edu);
			String str=edu.getListAttach().trim();
			JSONArray json=JSONArray.fromObject(str);
        
			for(int i=0;i<json.size();i++){

				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				Attach attach=new Attach();
				attach.setMessage_no(edu.getEducation_id());
				attach.setAttach_type(6);
				attach.setTitle(title);
				attach.setAttach_ext(attach_ext);
				attach.setAttach_path(attach_path);
				attach.setAttach_size(attach_size);				
				attach.setOrg_id((String) session.getAttribute("org_id"));
				attach.setOpt_user_id(user_id);
				listAttach.add(attach);
								
			}        
        }
		
		//System.out.println("修改：1");
		if(edu.getAttach()!=null&&!edu.getAttach().trim().isEmpty()){
			//System.out.println("修改：2");
			List<Attach> oldattach=attachDao.findAttachByMesNoAndType(edu.getEducation_id(),Integer.valueOf(AttachUtil.party_education_lst_attach_type),org_id);
			if(oldattach.size()>0){
				//System.out.println("修改：3");
				Attach delattach=oldattach.get(0);
				//System.out.println("删除："+delattach);
				AttachUtil.removeFile(delattach.getAttach_path());
				attachDao.deleteAttach(delattach);
			}
			
			//System.out.println("e2="+edu);
			String str=edu.getAttach().trim();
			JSONArray json=JSONArray.fromObject(str);
        
			for(int i=0;i<json.size();i++){

				Object check=json.get(i);
				if("null".equals(check.toString())){
					continue;
				}
				JSONObject job = json.getJSONObject(i); // 遍历 jsonarray 数组，把每一个对象转成 json 对象
				
	
				String attach_ext=(String)job.get("attach_ext");
				String attach_path=(String)job.get("attach_path");
				String attach_size=(String)job.get("attach_size");
				String title=(String)job.get("title");
				
				Attach attach2=new Attach();
				attach2.setMessage_no(edu.getEducation_id());
				attach2.setAttach_type(601);
				attach2.setTitle(title);
				attach2.setAttach_ext(attach_ext);
				attach2.setAttach_path(attach_path);
				attach2.setAttach_size(attach_size);				
				attach2.setOrg_id((String) session.getAttribute("org_id"));
				attach2.setOpt_user_id(user_id);
				listAttach.add(attach2);
								
			}        
        }
		List<Attach> newListAttach=FileUtil.moveFile(listAttach,"party_work");
			
		if(newListAttach!=null){
		for(Attach attach:newListAttach){
			attachDao.insertAttach(attach);
				
			}
		}
		
		//
		if(dept_ids!=null&&dept_ids.length>0){
			//System.out.println("1="+Arrays.toString(dept_ids));
			//修改关联党支部
			String dept_ids_param[] = ArrayUtil.insArray(dept_ids,dept_id_send);
			//System.out.println(Arrays.toString(dept_ids_param));
			//System.out.println("2="+Arrays.toString(dept_ids_param));
			
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("dept_ids", dept_ids_param);
			map.put("education_id",edu.getEducation_id());
			educationDeptDao.deleteEduDeptByEduIdAndDeptId(map);
			
			String old_dept_ids[] = educationDeptDao.findDeptIdByEduId(edu.getEducation_id());
			//System.out.println("3="+Arrays.toString(old_dept_ids));
			
			String new_dept_ids[] = ArrayUtil.resArray(dept_ids_param, old_dept_ids);
			//System.out.println("4="+Arrays.toString(new_dept_ids));
			
			//System.out.println(Arrays.toString(old_dept_ids));
			//System.out.println(Arrays.toString(new_dept_ids));
			
			if(new_dept_ids!=null&&new_dept_ids.length>0){
				List<EducationDept> list = new ArrayList<EducationDept>();
				EducationDept eduDept = null;
				
				for(int i=0;i<new_dept_ids.length;i++){
					eduDept = new EducationDept();
					eduDept.setEducation_id(edu.getEducation_id());
					eduDept.setDept_id(new_dept_ids[i]);
					eduDept.setCreate_date(new Timestamp(new Date().getTime()));
					eduDept.setOpt_user_id(user_id);
					eduDept.setOrg_id((String)session.getAttribute("org_id"));
					list.add(eduDept);
				}
				/*String dept_id_sends[] = {dept_id_send};
				String new_dept_id_sends[] = ArrayUtil.resArray(dept_id_sends,dept_ids);
				
				if(new_dept_id_sends!=null&&new_dept_id_sends.length>0){
					eduDept = new EducationDept();
					eduDept.setEducation_id(edu.getEducation_id());
					eduDept.setDept_id(dept_id_send);
					eduDept.setCreate_date(new Timestamp(new Date().getTime()));
					eduDept.setOpt_user_id(user_id);
					eduDept.setOrg_id((String)session.getAttribute("org_id"));
					list.add(eduDept);
				}*/
				educationDeptDao.addAllEduDept(list);
			}
		}else{
			educationDeptDao.deleteEduDeptByEduId(edu.getEducation_id());
		}
		return n;
	}

	public DeptAndEducation findEduById(String education_id, HttpServletRequest req) throws EduNotFoundException {
		if(education_id==null||education_id.trim().isEmpty()){
			throw new EduNotFoundException("选择查询的学习");
		}
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		DeptAndEducation dae = educationDao.findEduById(education_id,org_id);
		if(dae==null){
			throw new EduNotFoundException("此学习不存在");
		}		
		return dae;
	}

	public List<DeptAndEducation> findAllEdu(FindEduParam param, HttpServletRequest req) throws EduNotFoundException {
		System.out.println(param);
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		Integer page = param.getPage();
		Integer limit = param.getLimit();
		Integer start = null;
		if(limit==null&&page!=null){
			limit = paging.getPageSize();
			start=(page-1)*limit;
		}
		if(page==null){
			start = null;
			limit = null;
		}
		if(limit!=null&&page!=null){
			start = limit*(page-1);
		}		
		param.setStart(start);
		/*String dept_id = (String) session.getAttribute("dept_id");
		param.setDept_id(dept_id);*/
		param.setOrg_id(org_id);
		List<DeptAndEducation> list = educationDao.findAllEdu(param);
		
		return list;
	}

	public String findAllEduCount(FindEduParam param, HttpServletRequest req) throws EduNotFoundException {
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}	
		param.setOrg_id(org_id);
		String str = educationDao.findAllEduCount(param);
		return str;
	}
	
	public List<DeptAndEducation> findAllEduNoIssue(FindEduParam param, HttpServletRequest req) throws EduNotFoundException {
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		Integer page = param.getPage();
		Integer limit = param.getLimit();
		Integer start = null;
		if(limit==null&&page!=null){
			limit = paging.getPageSize();
			start=(page-1)*limit;
		}
		if(page==null){
			start = null;
			limit = null;
		}
		if(limit!=null&&page!=null){
			start = limit*(page-1);
		}		
		param.setStart(start);
		/*String dept_id = (String) session.getAttribute("dept_id");
		param.setDept_id(dept_id);*/
		param.setOrg_id(org_id);
		List<DeptAndEducation> list = educationDao.findAllEduNoIssue(param);
		
		return list;
	}

	public String findAllEduCountNoIssue(FindEduParam param, HttpServletRequest req) throws EduNotFoundException {
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		param.setOrg_id(org_id);
		String str = educationDao.findAllEduCountNoIssue(param);
		return str;
	}

	public Education findEdu(String education_id, HttpServletRequest req) throws EduNotFoundException {
		if(education_id==null||education_id.trim().isEmpty()){
			throw new EduNotFoundException("选择查询的学习");
		}
		HttpSession session = req.getSession();
		String org_id = (String) session.getAttribute("org_id");
		if(org_id==null){
			throw new EduNotFoundException("重新登录");
		}
		Education dae = educationDao.findEdu(education_id,org_id);
		if(dae==null){
			throw new EduNotFoundException("此学习不存在");
		}		
		return dae;		
	}
	
	/**
	 * 发布
	 */
	public int issueEdu(String education_ids[], HttpServletRequest req) throws EduNotFoundException {
		HttpSession session = req.getSession();
		String user_id = (String) session.getAttribute("id");
		String dept_id = (String)session.getAttribute("dept_id");
		String org_id = (String)session.getAttribute("org_id");
		if(user_id==null){
			throw new EduNotFoundException("重新登录");
		}
		
		if(education_ids==null){
			throw new EduNotFoundException("选择未发布的学习");
		}
		if(education_ids.length<1){
			throw new EduNotFoundException("请选择未发布的学习");
		}
		if(dept_id==null||dept_id.trim().isEmpty()){
			throw new EduNotFoundException("当前账号不归属党支部，无权限");
		}
		List<String> list = Arrays.asList(education_ids);
		int n = educationDao.issueEdu(org_id,list);
		if(n<1){
			throw new EduNotFoundException("发布失败");
		}
		
		//添加党支部积分
		Pb_Integral_RuleParam param = new Pb_Integral_RuleParam();
		param.setStart(0);
		param.setEnd(1);
		List<Pb_Integral_Rule> listRule = pb_Integral_RuleDao.findPb_Integral_RuleByParam(param);
		System.out.println(listRule);
		
		Integer integral_val=0;		
		Pb_Integral_Rule rule = listRule.get(0)==null?null:listRule.get(0);
		if(rule!=null){
			integral_val = rule.getLearn_send_val();
		}
		OrganizeEntity organize = organizeDao.findOrganizeByDeptId(dept_id,org_id);
		
		String log_des = organize==null?"":organize.getDept_name();
		log_des = log_des+"于"+new Timestamp(new Date().getTime())+"发布教育学习，获取积分"+integral_val+"分";
		for(int j=0;j<education_ids.length;j++){
			Pb_Integral_Dept_Log entity = new Pb_Integral_Dept_Log();
			entity.setIntegral_val(integral_val);
			entity.setLog_flag("2");
			entity.setLog_des(log_des);
			entity.setDept_id(dept_id);
			entity.setState("Y");
			entity.setOrg_id(org_id);
			entity.setCreate_date(new Timestamp(new Date().getTime()));
			entity.setOpt_user_id(user_id);
			entity.setInfo_id(education_ids[j]);			
			pb_Integral_Dept_LogDao.savePb_Integral_Dept_Log(entity);
		}
		
		
		return n;
	}

	

}
